//
//  Diary.swift
//
//
//  Created by Jiang Chencheng on 2024/9/11.
//

import Vapor
import Fluent
import struct Foundation.UUID

final class Diary: Model, @unchecked Sendable {
    
    static let schema = "diary"
    
    @ID(key: .id)
    var id: UUID?
    
    @Field(key: "content")
    var content: String
    
    @Parent(key: "room_id")
    var room: Room
    
    @Timestamp(key: "created_at", on: .create)
    var createdAt: Date?

    @Timestamp(key: "updated_at", on: .update)
    var updatedAt: Date?
    
    @Timestamp(key: "deleted_at", on: .delete)
    var deletedAt: Date?
    
    init() { }
    
    init(id: UUID? = nil, content: String) {
        self.id = id
        self.content = content
    }
    
    
    func toDTO() -> DiaryDTO {
        .init(
            id: self.id,
            content: self.content
        )
    }
}


